package com.easyskool.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;


public class killUtil {
public static void main(String qq[]) throws ClassNotFoundException, SQLException
{
	//STEP 2: Register JDBC driver
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = null;
    //STEP 3: Open a connection
    System.out.println("Connecting to database...");
    try {
		conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/easyskool?zeroDateTimeBehavior=convertToNull","easyskool","");
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

    //STEP 4: Execute a query
    System.out.println("Creating statement...");
    Statement stmt = conn.createStatement();
    String sql;
    sql = "select id from information_schema.processlist";
    ResultSet rs = stmt.executeQuery(sql);

    ArrayList<String> pid=new ArrayList<String>();
    //STEP 5: Extract data from result set
    while(rs.next()){
    	System.out.println(rs.getString(1));
    	pid.add(rs.getString(1));
    }
    conn.close();
    Connection conn1=null;
//    try {
		conn1 =null;// DriverManager.getConnection("jdbc:mysql://103.21.58.5:3306/easyskool?zeroDateTimeBehavior=convertToNull","easyskool","easyskool");
//	} catch (SQLException e) {
//		// TODO Auto-generated catch block
//		e.printStackTrace();
//	}
for( int i=1;i<pid.size();i++)
{ Statement stmt1 = conn1.createStatement();
String sql1;
System.out.println("Killing "+pid.get(i));
sql1 = "kill "+pid.get(i);
ResultSet rs1 = stmt1.executeQuery(sql1);
	
	}
}
}
